from django.db import models
from user.models import User
from goods.models import Table

# Create your models here.
class Orders(models.Model):
    "订单"
    # 订单编号是19位， id 是订单的索引号
    order_id = models.CharField(primary_key=True, auto_created=False,max_length=20, verbose_name="订单编号")
    usere = models.ForeignKey(User, on_delete=models.CASCADE)
    created_time = models.DateTimeField(verbose_name="创建时间")

    class Meta:
        db_table = 'orders'


class OrderGoods(models.Model):
    "订单商品表"
    order = models.ForeignKey(Orders, on_delete=models.CASCADE)
    good = models.ForeignKey(Table, on_delete=models.CASCADE)
    count = models.IntegerField(default=0, verbose_name="商品数量")
    price = models.DecimalField(max_digits=13, decimal_places=2, verbose_name="商品价格")

    class Meta:
        db_table = 'ordergoods'
